home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ufsl.lzh / UFSL / FONTTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  4.2 KB  |  170 lines

  1. /**************************************************************************
  2. *
  3. *                    Universal Fontselector Version 0.96
  4. *                     (c) 1991-1993 by Michael Thänitz
  5. *
  6. **************************************************************************/
  7. #include <portab.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <aes.h>
  12. #include <vdi.h>
  13. #include <tos.h>
  14.  
  15. #include "ufsl.h"
  16.  
  17. #define SCREEN 1
  18. #define MONO   1
  19.  
  20. static int work_in[103],work_out[57];
  21. int aeshandle, vdihandle;
  22. char alertstr[256];
  23.  
  24. int cdecl fontsel_init(void); 
  25. int cdecl fontsel_input(int vdihandle, int dummy, int ftype, char *text, int *id, int *size);
  26.  
  27. /* ----- Cookie Jar -------------------------------------------------------- */
  28.  
  29. typedef struct
  30. {
  31.     long    id,
  32.         *ptr;
  33. } COOKJAR;
  34.  
  35. /* ------------------------------------------------------------------------- */
  36. /* ----- get_cookie -------------------------------------------------------- */
  37. /* ------------------------------------------------------------------------- */
  38.  
  39. static long *get_cookie(long cookie)
  40. {
  41.     long    sav;
  42.     COOKJAR    *cookiejar;
  43.     int    i = 0;
  44.  
  45.     sav = Super((void *)1L);
  46.     if(sav == 0L)
  47.         sav = Super(0L);
  48.     cookiejar = *((COOKJAR **)0x05a0l);
  49.     if(sav != -1L)
  50.         Super((void *)sav);
  51.     if(cookiejar)
  52.     {
  53.         while(cookiejar[i].id)
  54.         {
  55.             if(cookiejar[i].id == cookie)
  56.                 return(cookiejar[i].ptr);
  57.             i++;
  58.         }
  59.     }
  60.     return(0l);
  61. }
  62.  
  63. static int open_work (int device)
  64. {
  65.    register int i;
  66.    int handle;
  67.  
  68.    for (i = 0; i < 103; i++) work_in [i] = 1;
  69.    work_in [0]  = device;                         /* device handle */
  70.    work_in [10] = 2;                         /* Raster Koordinaten */
  71.  
  72.    if (device == SCREEN)
  73.    {
  74.      handle=aeshandle;
  75.      v_opnvwk (work_in, &handle, work_out);     /* virtuell öffnen */
  76.    }
  77.    else                                        /* nicht Bildschirm */
  78.    {
  79.      v_opnwk (work_in, &handle, work_out);  /* physikalisch öffnen */
  80.    }
  81.    return (handle);
  82. }
  83.  
  84. static void close_work (int handle, int device)
  85. {
  86.   switch (device)
  87.   {
  88.     case SCREEN:
  89.        v_clsvwk (handle);
  90.        break;
  91.     default:
  92.        v_clswk (handle);
  93.        break;
  94.   }
  95. }
  96.  
  97. void cdecl helpfunc()
  98. {
  99.    form_alert(1,"[0][|Hilfstext][  OK  ]");
  100. }
  101.  
  102. main()
  103. {
  104.    int ret,id,size,n_fonts,done=FALSE;
  105.    UFSL *ufsl;
  106.  
  107.    appl_init();
  108.    graf_mouse(ARROW,NULL);
  109.    aeshandle=graf_handle(&ret,&ret,&ret,&ret);
  110.    vdihandle=open_work(SCREEN);
  111.  
  112.    if(vq_gdos())
  113.       vst_load_fonts(vdihandle,0);
  114.  
  115.    ufsl=(UFSL *)get_cookie('UFSL');
  116.    if(ufsl)
  117.    {
  118.        do
  119.       {
  120.             ufsl->fontsel_init(); /* IMMER vorher aufrufen!!! */
  121.           ufsl->dialtyp=DIALOG;
  122.           ufsl->helpbutton->ob_width=7*(strlen("HILFE")+3);
  123.           ufsl->helpbutton->ob_flags=SELECTABLE|EXIT;
  124.           ufsl->helpbutton->ob_state=OUTLINED|SHADOWED;
  125.           ufsl->helpbutton->ob_spec.tedinfo->te_font=SMALL;
  126.           strcpy(ufsl->helpbutton->ob_spec.tedinfo->te_ptext,"HILFE");
  127.           ufsl->helpfunc=helpfunc;
  128.           ufsl->msgfunc=NULL;
  129.            switch(ufsl->fontsel_input(vdihandle,0,0,"Bitte Font auswählen",&id,&size))
  130.            {
  131.               case 1:
  132.                  sprintf(alertstr,"[1][|FontId: %d, Fontgröße: %dpt.][  OK  ]",id,size);
  133.                  form_alert(1,alertstr);
  134.                vst_font(vdihandle,id);
  135.                   vst_point(vdihandle,size,&ret,&ret,&ret,&ret);
  136.                  break;
  137.               case 0:
  138.                  form_alert(1,"[1][|Abbruch gewählt. ][  OK  ]");
  139.                  done=TRUE;
  140.                  break;
  141.               case -1:
  142.                  form_alert(1,"[3][|Out of Memory! ][  OK  ]");
  143.                  done=TRUE;
  144.                  break;
  145.               case -2:
  146.                  form_alert(1,"[3][|Mehrfachaufruf nicht möglich! ][  OK  ]");
  147.                  done=TRUE;
  148.                  break;
  149.               case -3:
  150.                  form_alert(1,"[3][|Fontgröße konnte nicht|identifiziert werden! ][  OK  ]");
  151.                  done=TRUE;
  152.                  break;
  153.               case -4:
  154.                  form_alert(1,"[3][|Anzahl Fonts muß|größer null sein! ][  OK  ]");
  155.                  done=TRUE;
  156.                  break;
  157.            }
  158.        }
  159.        while(!done);
  160.     }
  161.    else
  162.       form_alert(1,"[1][|Kein gültiger UFSL-Cookie! ][  OK  ]");
  163.  
  164.    if(vq_gdos())
  165.       vst_unload_fonts(vdihandle,0);
  166.    close_work(vdihandle,SCREEN);
  167.    appl_exit();
  168. }
  169.  
  170.